﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Home : System.Web.UI.Page
{
    CustormerMethord CM = new CustormerMethord();
    static PagedDataSource p = new PagedDataSource();
    public static int stt;
    public static int home_page = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        LoadData();
    }

    public void LoadData()
    {
        DataTable dt = CM.ViewallProduct();
        p.DataSource = dt.DefaultView;
        p.PageSize = 9;
        p.CurrentPageIndex = home_page;
        p.AllowPaging = true;
        btnFirst.Enabled = true; Button1.Enabled = true; Button2.Enabled = true; btnLast.Enabled = true;

        if (p.IsFirstPage == true)
        {
            btnFirst.Enabled = false;
            Button1.Enabled = true;
            Button2.Enabled = false;
            btnLast.Enabled = true;
        }

        if (p.IsLastPage == true)
        {
            btnFirst.Enabled = true;
            Button1.Enabled = false;
            Button2.Enabled = true;
            btnLast.Enabled = false;
        }

        txtQuantity.Text = (home_page + 1) + " / " + p.PageCount;

        dlProduct.DataSource = p;
        dlProduct.DataBind();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        home_page++;
        LoadData();

    }
    protected void btnFirst_Click(object sender, EventArgs e)
    {
        home_page = 0;
        LoadData();
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        home_page--;
        LoadData();

    }
    protected void btnLast_Click(object sender, EventArgs e)
    {
        home_page = p.PageCount - 1;
        LoadData();
    }
    protected void dlProduct_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "Details")
        {
            Label ProductId = (Label)e.Item.FindControl("lblID");
            Response.Redirect("ProductDetails.aspx?ProID=" + ProductId.Text + "");
        }
    }
}